package com.jt.demo51.pp02;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JDkproxy {
    public static Object getObject(Object target){
        ClassLoader classLoader = target.getClass().getClassLoader();
        Class<?>[] interfaces = target.getClass().getInterfaces();
        return Proxy.newProxyInstance(classLoader, interfaces, getInvocationHandler(target));
    };

    public static InvocationHandler getInvocationHandler(Object target){
        return new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                Object result=null;
                System.out.println("入库1");
                result = method.invoke(target, args);
                System.out.println("入库2");
                return result;
            }
        };

    }


}
